//
//  FnRewardVideoAd.m
//  flutter_fn_sdk
//
//  Created by xiaomin huang on 2022/7/4.
//

#import "FnRewardVideoAd.h"
#import "FnSdkHeader.h"

@interface FnRewardVideoAd ()<FNLoadReardVideoAdDelegate>

@property (nonatomic,strong)FNInitalizeRardVideo *rardVideo;

@end

@implementation FnRewardVideoAd

+ (instancetype)loadAdWithAppId:(NSString *)appId adsId:(NSString *)adsId isRelease:(BOOL)release userId:(NSString *)userId
                      extraInfo:(NSString *)info{
    return [[FnRewardVideoAd alloc] initWithAppId:appId adsId:adsId isRelease:release userId:userId extraInfo:info];
}

- (instancetype)initWithAppId:(NSString *)appId adsId:(NSString *)adsId isRelease:(BOOL)release userId:(NSString *)userId
                    extraInfo:(NSString *)info{
    if (self = [super init]) {
        self.rardVideo = [[FNInitalizeRardVideo alloc] initWithPlacementId:appId adsId:adsId];
        self.rardVideo.isRelease = release;
        self.rardVideo.userIdentifier = userId;
        self.rardVideo.extraInfo = info;
        self.rardVideo.delegate = self;
        [self.rardVideo loadFnRerdVideoAd];
        
//        UIWindow *window = [UIApplication sharedApplication].delegate.window;
//        UIViewController *rootVC = window.rootViewController;
//        [self.rardVideo loadAndShowFnRerdVidelAd:rootVC];
    }
    return self;
}

/**
 视频广告加载成功回调
 */
- (void)fnRewardVideoAdDidLoad{
    if (self.onLoad) {
        self.onLoad();
    }
}


/**
 视频广告曝光回调
 */
- (void)fnRewardVideoShow{
    if (self.onShow) {
        self.onShow();
    }
}

/**
 视频播放页关闭回调
 */
- (void)fnRewardVideoClosed{
    if (self.onClosed) {
        self.onClosed();
    }
}


/**
 视频广告各种错误信息回调
 @param error 具体错误信息
 */
- (void)fnRewardVideoError:(NSError *)error{
    NSLog(@"激励广告错误：%@", error);
    if (self.onError) {
        self.onError(error);
    }
}


/**
 视频广告播放达到激励条件回调
 @param orderId 订单ID
 */
- (void)fnRewardVideoReward:(NSString *)orderId{
    if (self.onReward) {
        self.onReward(orderId);
    }
}


/**
 视频广告点击回调
 */
- (void)fnRewardVideoClicked{
    if (self.onClicked) {
        self.onClicked();
    }
}

- (void)dealloc{
    self.rardVideo.delegate = nil;
    NSLog(@"FnRewardVideoAd - dealloc");
}

@end
